<template>
  <div>
    <el-card header="请登录">
      <el-form label-width="60px" @submit.native.prevent="login">
        <el-form-item label="用户名">
          <el-input v-model="model.name"></el-input>
        </el-form-item>
        <el-form-item label="密码">
          <el-input type="password" v-model="model.pwd"></el-input>
        </el-form-item>
        <el-form-item label-width="0">
          <el-button type="primary" native-type="submit" style="margin:0 auto;display:block;">登录</el-button>
        </el-form-item>
      </el-form>
    </el-card>
  </div>
</template>

<script>
export default {
  data () {
    return {
      model: {
        name: 'admin',
        pwd: '123456'
      }
    }
  },
  methods: {
    async login () {
      const { data: res } = await this.$http.post('/login', this.model)
      localStorage.token = res.token
      this.$message.success('登录成功')
      this.$router.push('/')
    }
  }
}
</script>

<style lang="less" scoped>
.el-card {
  width: 25rem;
  margin: 25vh auto;
}
</style>
